package com.sharepics.servlets;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Text;

public class UploadPictureServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3900691235632720110L;
	/**
	 * 
	 */
	
	private static final Logger log =
        Logger.getLogger(UploadPictureServlet.class.getName());

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
		
		log.info("GET Upload-----------------");
	}
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
		
		log.info("POST Upload-----------------");
		
		
		BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
		Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
        BlobKey blobKey = blobs.get("uploadedfile");
        log.info("KEY : " +blobKey.getKeyString());
        resp.getOutputStream().print(blobKey.getKeyString());
        resp.getOutputStream().flush();
        resp.getOutputStream().close();
	}
}

